package com.rain.rainspringboot3.encryption.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.rain.rainspringboot3.encryption.entity.User;
import com.rain.rainspringboot3.encryption.entity.UserDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;


import java.util.List;

/**
 * 用户数据访问接口
 */
@Mapper
public interface User1Mapper extends BaseMapper<User> {

    @Mapping(target = "phoneSensitiveId", source = "phone")
    @Mapping(target = "idCardSensitiveId", source = "idCard")
    @Mapping(target = "emailSensitiveId", source = "email")
    @Mapping(target = "createTime", ignore = true) // 假设不从DTO传
    User toUserVO(UserDTO userDTO);
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM t_user WHERE username = #{username}")
    User findByUsername(@Param("username") String username);
    
    /**
     * 查询所有用户（用于测试批量解密）
     */
    @Select("SELECT * FROM t_user")
    List<User> findAll();
}